<template>
  <!-- 查看详情 -->
  <div>
    <el-dialog
      title="工单详情"
      :visible.sync="dialogVisible"
      width="50%"
    >
      <!-- 查看详情 -->
      <div class="detail">
        <div class="todo">
          <img v-if="orderdata.taskStatus===1" src="@/assets/time.png" alt="" class="image">
          <img v-if="orderdata.taskStatus===3" src="@/assets/cancel.png" alt="" class="image">
          <span class="text">{{ orderdata.taskStatus===1? '待办':orderdata.taskStatus===2? '进行':orderdata.taskStatus===3? '取消':'' }}</span>
          <img v-if="orderdata.taskStatus===1" src="https://likede2-admin.itheima.net/img/pic_1.834b274c.png" alt="" class="images">
          <img v-if="orderdata.taskStatus===3" src="https://likede2-admin.itheima.net/img/pic_3.e8208e34.png" alt="" class="images">
        </div>
        <!-- 待办 -->
        <div v-if="orderdata.taskStatus===1">
          <el-row>
            <el-col :span="12">
              <div class="left">
                <p>设备编号：<span>{{ orderdata.innerCode }}</span></p>
                <p>运营人员：<span>{{ orderdata.userName }}</span></p>
                <p>补货数量：<el-button type="text" @click="viewGoods">补货详情</el-button></p>
                <p>备注：<span>{{ orderdata.desc }}</span></p>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="left">
                <p>创建日期：<span>{{ orderdata.createTime.replace('T',' ') }}</span></p>
                <p>工单类型：<span>{{ orderdata.taskType.typeName }}</span></p>
                <p>工单方式：<span>{{ orderdata.createType? '手动':'自动' }}</span></p>
              </div>
            </el-col>
          </el-row>
        </div>
        <!-- 取消 -->
        <div v-if="orderdata.taskStatus===3">
          <el-row>
            <el-col :span="12">
              <div class="left">
                <p>设备编号：<span>{{ orderdata.innerCode }}</span></p>
                <p>取消日期：<span>{{ orderdata.updateTime.replace('T',' ') }}</span></p>
                <p>工单类型：<span>{{ orderdata.taskType.typeName }}</span></p>
                <p>工单方式：<span>{{ orderdata.createType? '手动':'自动' }}</span></p>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="left">
                <p>创建日期：<span>{{ orderdata.createTime.replace('T',' ') }}</span></p>
                <p>运营人员：<span>{{ orderdata.userName }}</span></p>
                <p>补货数量：<el-button type="text" @click="viewGoods">补货详情</el-button></p>
                <p>取消原因：<span>{{ orderdata.desc }}</span></p>
              </div>
            </el-col>
          </el-row>
        </div>

      </div>

      <span slot="footer">
        <!-- 查看详情的取消 -->
        <div class="foot">
          <el-button v-if="orderdata.taskStatus===1" style="background-color: #fbf4f0;color: #606266;" @click="cancel">取消订单</el-button>
          <el-button v-if="orderdata.taskStatus===3" style="background-color: #fbf4f0;color: #606266;" @click="rebuild">重新创建</el-button>
        </div>
      </span>
    </el-dialog>

    <!-- 货物详情弹窗 -->
    <GoodsList ref="goods" :type="type" />

    <!-- 重现创建，打开新建弹窗 -->
    <AddDialog ref="readd" />
  </div>
</template>

<script>
import { getOrderDetail, getOrderCancel } from '@/api/lmoperation'

import GoodsList from './goodsDetail.vue'
// 新建
import AddDialog from './dialogAdd.vue'

export default {
  name: 'ViewDialog',
  components: {
    GoodsList,
    AddDialog
  },
  props: {
  },
  data() {
    return {
      dialogVisible: false,
      // 工单详情
      orderdata: {},
      type: '',
      row: {}
    }
  },
  methods: {
    // 弹窗显示
    openDialogK() {
      this.dialogVisible = true
    },
    // 弹窗关闭
    offDialogG() {
      this.dialogVisible = false
    },
    // 获取工单的详情
    async getOrdersDetail(row) {
      console.log(row)
      this.row = row
      const taskId = row.taskId
      const data = await getOrderDetail(taskId)
      this.orderdata = { ...data }
      // console.log(data)
    },
    // 查看补货详情
    viewGoods() {
      this.type = 'view'
      this.$refs.goods.showDialog(this.orderdata.taskId)
    },
    // 查看详情的取消
    cancel() {
      this.$confirm('取消工单后,将不能恢复， 是否确认取消?', '', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await getOrderCancel(this.orderdata)
        this.$message.success('取消成功!')
        this.offDialogG()
      }).catch(() => {
        console.log('取消')
      })
    },
    // 重新创建
    rebuild() {
      this.$refs.readd.showDialog(this.row)
    }
  }
}
</script>

<style scoped lang='scss'>
.footer{
  padding-right: 36%;
}
.foot{
  padding-right: 42%;
}
.detail{
  width: 100%;
  height: 200px;
  .todo{
    width: 100%;
    height: 50px;
    line-height: 50px;
    background-color: #f8f8f8;
    margin-bottom: 20px;
    padding-left: 20px;
    padding-right: 80px;
    .image{
      vertical-align: middle;
    }
    .text{
      font-size: 16px;
      margin-left: 10px;
      display: inline-block;
      vertical-align: middle;
    }
    .images{
      width: 14%;
      float: right;
    }
  }
  .left{
    padding-left: 50px;
  }
}
</style>
